/**
 * 
 */
package com.tx.core.extend;

import java.util.Arrays;

/**
 * 
 * @author wanghy
 * @since 2013-6-7
 * 
 */
public class EmployeeSortTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Emp[] staff = new Emp[3];
		
		staff[0] = new Emp("Harry", 35000);
		staff[1] = new Emp("Carl", 75000);
		staff[2] = new Emp("Tony", 38000);
		
		Arrays.sort(staff);
		
		for (Emp e : staff) {
			System.out.println(e);
		}
	}

}

class Emp implements Comparable<Emp> {

	private String name;
	
	private double salary;
	
	public Emp(String n, double s) {
		name = n;
		salary = s;
	}
	
	public int compareTo(Emp other) {
		if (salary < other.salary){
			return -1;
		}
		if (salary > other.salary){
			return 1;
		}
		return 0;
	}

	@Override
	public String toString() {
		return getClass().getName() +
				"[name=" + name +
				", salary=" + salary +
				"]";
	}
}
